package controller;

import model.BlogDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-25
 * Time：10:51
 */
@WebServlet("/deleteblog")
public class AdminDeleteBlogServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");

        String userId = req.getParameter("userId");
        if (userId == null) {
            System.out.println("传参错误");
            resp.setStatus(403);
        }

        String blogId = req.getParameter("blogId");
        if (blogId==null) {
            System.out.println("传参错误");
            resp.setStatus(403);
        }
        int bId = Integer.parseInt(blogId);
        BlogDao blogDao = new BlogDao();
        blogDao.delete(bId);

        resp.sendRedirect("blog_check.html?userId=" + userId);
        resp.setStatus(200);
    }
}
